<template>
    <div style="background-color: #f9f9f9;width: 100%" v-bind:style="{height:iframeHeight+'px'}">
        <van-nav-bar
                title="转入"
                left-text="返回"
                right-text="保存二维码"
                left-arrow
                @click-left="onClickLeft"
                @click-right="onClickRight"
        />
        <!--<div :style="{textAlign: 'center',marginTop:'50px'}">-->
        <!--<img :src="'http://api.yyw66.cn/api/index.php/user/pay/qrCode?user_id='+user_id"/>-->
        <!--</div>-->
        <div style="padding: 20px;">
            <div style="
        border-radius: 10px;text-align: center;
        margin: 25px auto;
        background-color: #ffffff;box-shadow: 0px 0px 20px #ddd;
padding-bottom:10px;">
                <span style="line-height: 60px">扫一扫，向我付款</span>
                <img :src="'http://api.yyw66.cn/api/index.php/user/pay/qrCode?user_id='+user_id"
                     style="width: 100%;"
                />
            </div>
        </div>
        <!--<div :style="{textAlign:'center'}">-->
        <!--<span  class="button" @click="MeEnter">我的转入</span>-->
        <!--</div>-->
        <div class="button">
            <span @click="MeEnter">我的转入</span>
        </div>
    </div>
</template>

<script>
    import Vue from 'vue'
    import {NavBar, Lazyload, Button} from 'vant';

    Vue.use(NavBar, Lazyload, Button);
    import {QrCode} from "../api/data";

    export default {
        data() {
            return {
                fixed: true,
                img: 'https://img.yzcdn.cn/2.jpg',
                user_id: '',
                iframeHeight: ''
            }
        },
        methods: {
            onClickLeft() {
                this.$router.back()
            },
            onClickRight() {
                document.addEventListener("plusready", onPlusReady, false);
                var r = null;

                function onPlusReady() {
                }

                var dtask = plus.downloader.createDownload("http://api.yyw66.cn/api/index.php/user/pay/qrCode?user_id=" + this.user_id,
                    {}, function (d, status) {
                        // 下载完成
                        if (status == 200) {
                            plus.gallery.save(d.filename, function () { //保存到相册
                                plus.io.resolveLocalFileSystemURL(d.filename, function (enpty) {
                                    mui.toast('保存成功')
                                });
                            })
                        } else {
                            alert('下载失败');
                        }
                    });
                //dtask.addEventListener( "statechanged", onStateChanged, false );
                dtask.start();
            },
            MeEnter() {
                this.$router.push({
                    path: `./balance`
                })
            }
        },
        created() {
            let userid   = JSON.parse(localStorage.getItem('user'))
            let user_id  = userid.id
            this.user_id = user_id;
        },
        mounted() {
            this.iframeHeight = document.documentElement.clientHeight;
            // this.see(this.$route.query.url)
        }
    }
</script>

<style scoped>
    .button {
        width: 100%;
        height: 50px;
        text-align: center;
    }

    .button span {
        line-height: 30px;
        width: 100px;
        margin: 0 auto;
    }
</style>
